package com.zmn.oms.task.job.order;

import com.alibaba.fastjson.JSON;
import com.github.ltsopensource.core.domain.Action;
import com.github.ltsopensource.core.domain.Job;
import com.github.ltsopensource.spring.tasktracker.JobRunnerItem;
import com.github.ltsopensource.spring.tasktracker.LTS;
import com.github.ltsopensource.tasktracker.Result;
import com.zmn.oms.manager.utils.TaskConsts;
import com.zmn.oms.model.dto.order.create.CreateOrderFailMessage;
import com.zmn.oms.services.interfaces.order.OrderChangeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 类描述：订单创建失败后的定时重试处理任务
 *
 * @author lhl
 * @date 2020/02/19 3:25
 */
@Slf4j
@LTS
public class OrderCreateFailJob {

    @Autowired
    private OrderChangeService orderChangeService;

    @JobRunnerItem(shardValue = TaskConsts.TASK_ID_ORDER_CREATE_FAIL)
    public Result resendCreateOrderFailMessage(Job job) {
        String message = job.getParam("createOrderFailMessage");
        CreateOrderFailMessage createOrderFailMessage = JSON.parseObject(message, CreateOrderFailMessage.class);

        orderChangeService.orderCreateFailSyncToApi(createOrderFailMessage);

        return new Result(Action.EXECUTE_SUCCESS, "执行成功了!");
    }
}
